package com.suixun.service.information.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import com.suixun.dao.ZxArticleZanMapper;
import com.suixun.entity.ZxArticleZan;
import com.suixun.entity.ZxArticleZanExample;
import com.suixun.service.information.ZxArticleZanService;

@Service
public class ZxArticleZanServiceImpl implements ZxArticleZanService{
    
    @Resource
    private ZxArticleZanMapper zxArticleZanMapper;

    @Override
    public void add(Integer articleId, Integer userId) {
       
        ZxArticleZan zan = new ZxArticleZan(); 
        zan.setArticleId(articleId);
        zan.setUserId(userId);
        zan.setCreateTime(new Date());
        zxArticleZanMapper.insert(zan);
    }

    @Override
    public ZxArticleZan get(Integer articleId, Integer userId) {
        
        ZxArticleZanExample example = new ZxArticleZanExample();
        example.createCriteria().andArticleIdEqualTo(articleId).andUserIdEqualTo(userId);
        
        List<ZxArticleZan> list = zxArticleZanMapper.selectByExample(example);
        if(!CollectionUtils.isEmpty(list)){
            return list.get(0);
        }
        
        return null;
    }

}
